package com.example.demo.controller;

import Mapper.FoodMapper;
import Mapper.MoodMapper;
import entity.Food;
import entity.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class SearchController {

    @Autowired
    FoodMapper foodMapper;

    @Autowired
    MoodMapper moodMapper;

    //(首页)搜索情绪获得结果
    @PostMapping("/searchmood")
    public List<Food> searchmood(@RequestBody Request request) {

        System.out.println("搜索：" + request.getInput());

        List<Food> result = moodMapper.searchMoods(request.getInput());

        if (result.isEmpty()) {
            System.out.println("没有结果");
            return Collections.emptyList();
        } else {
            System.out.println(result.size());
            return result;
        }
    }



    //(食补)搜索食物获得结果
    @PostMapping("/searchfood")
    public List<Food> searchfood(@RequestBody Request request){
        System.out.println("搜索：" + request.getInput());

        List<Food> result = foodMapper.searchfoods(request.getInput());

        if (result.isEmpty()) {
            System.out.println("没有结果");
            return Collections.emptyList();
        } else {
            System.out.println(result.size());
            return result;
        }
    }


}




